//
//  UIBarButtonItem+Extension.m
//  RiceBasket
//
//  Created by DwZeng on 2021/1/15.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)
/**
 *  创建一个UIBarButtonItem
 *
 *  @param target    点击item之后调用哪个对象的方法
 *  @param action    点击item后调用的方法
 *  @param image     普通的图片
 *  @param highImage 高亮的图片
 *
 *  @return 返回一个UIBarButtonItem
 */
+ (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage{
    
    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //设置图片
    [itemButton setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [itemButton setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    
    //设置尺寸
    itemButton.size = itemButton.currentBackgroundImage.size;
    
    return [[UIBarButtonItem alloc] initWithCustomView:itemButton];
    
}
@end
